#include<graphics.h>
#include<iostream>
using namespace std;
#include"Timer.h"
#include"Camera.h"
#include"Atlas.h"
#include"Util.h"
#include"resources.h"
#include"Animation.h"
#include"Sence.h"
#include"Menu.h"
#include"Game.h"
#include"Selection.h"
#include"Sence_Manager.h"




const size_t FPS = 165;

Sence* menu_sence = nullptr;
Sence* game_sence = nullptr;
Sence* selector_sence = nullptr;
SenceManager sence_manager;
Camera _camera;

int main()
{
	load_resources();
	initgraph(1200, 800, EX_SHOWCONSOLE);
	bool running = true;
	ExMessage msg;
	BeginBatchDraw();

	menu_sence = new MenuSence();
	game_sence = new GameSence();
	selector_sence = new SelectorSence();
	sence_manager.set_current_sence(menu_sence);
	while (running)
	{
		DWORD start = GetTickCount();
		while (peekmessage(&msg))
		{
			sence_manager.on_input(msg);
		}

		static DWORD frame_start = GetTickCount();
		DWORD frame_end = GetTickCount();
		int frame_space = frame_end - frame_start;
		sence_manager.on_update(frame_space);
		frame_start = frame_end;

		cleardevice();
		sence_manager.on_draw();
		FlushBatchDraw();

		DWORD end = GetTickCount();
		DWORD dtime = end - start;
		if (dtime < 1000 / FPS)
		{
			Sleep(1000 / FPS - dtime);
		}
	}
	sence_manager.on_exit();
	EndBatchDraw();

	return 0;
}